package com.qf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.conmmon.R;
import com.qf.entity.Role;
import com.qf.entity.User;
import com.qf.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @propram: IntelliJ IDEA
 * @description:
 * @author: 秦先发
 * @create: 2021-09-27 20:34
 **/
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    /**
     * 添加角色
     * @param role
     * @return
     */
    @PostMapping("/addRole")
    public R addRole(@RequestBody Role role){
        return  R.getR(roleService.save(role));

    }

    /**
     * 删除角色
     */
    @GetMapping("/deleteRoleById")
    public R deleteRoleById(@RequestParam Integer id){
       return  R.getR(roleService.removeById(id));
    }

    /**
     * 修改角色
     */
    @PostMapping("/updateRole")
    public R updateRole(@RequestBody Role role){
        return R.getR(roleService.updateById(role));
    }
    /**
     * 查询所有角色
     */
    @PostMapping("/selectAllRole")
    public R selectAllRole(){
        return R.saveR("data",roleService.list());
    }
    /**
     * 根据id查询角色
     */
    @GetMapping("/selectRoleById")
    public R selectRoleById(@RequestParam Integer id){
        return R.saveR("data", roleService.getById(id));
    }
    /**
     * 分页查询用户信息
     *
     * @param page
     * @return
     */
    @PostMapping("/selectRolePage")
    public R selectRolePage(@RequestBody Page<Role> page) {
        Page<Role> list = roleService.page(page);
        return R.getR(list);
    }
    /**
     * 批量删除角色
     */
    @PostMapping("/deleteRoles")
    public R deleteRoles(@RequestBody List<Integer> ids){
        return R.getR(roleService.getBaseMapper().deleteBatchIds(ids));
    }
}
